Using & intersection. Intersection types are closely related to union types, but they are used very differently. An intersection type combines multiple types into one. This allows you to add together existing types to get a single type that has all the features you need.
We have a function that takes a parameter of type User with fields id and name. We now need to add an optional email field without modifying the original User definition. How would you extend the type?
Given an interface Config with properties url: string and timeout: number, you need to create a new type that includes all Config properties plus a retries?: number. Show the TypeScript code you would write.
Our codebase uses a third‑party library that declares an interface RequestOptions. We need to add a custom authToken property for our internal usage without forking the library. How would you extend the type, and what pitfalls should you watch for?
You refactored a component to accept a generic Props type, but later you need to add a new optional prop theme that should be available to all components. Explain how you would extend the existing props type and why a simple intersection might cause issues.
We're building a shared UI component library used across several services. Each service wants to augment the base ButtonProps with its own styling fields. How would you design the type extensions to allow safe augmentation while preventing breaking changes for existing consumers?
During a migration from a legacy JavaScript module to TypeScript, you need to add additional fields to a type exported by the legacy module without editing its source. Discuss how you would use declaration merging or module augmentation, and the trade‑offs regarding build time and type safety.
Our organization is standardizing on a core domain model defined in a central package. Multiple product teams need to extend these domain types with product‑specific attributes. How would you structure the type extensions and package boundaries to support independent evolution while keeping a single source of truth?
We plan to deprecate a set of internal types and replace them with a new version across dozens of microservices. Describe a strategy using TypeScript's module augmentation and versioned type namespaces to roll out the change gradually without breaking existing services.